package com.alibaba.citrus.ots.unified.inventory.utils;

import com.epoch.app.otsunifiedinventory.model.enums.AllocateApplyOrderHeaderEnum;
import com.epoch.app.otsunifiedinventory.model.enums.AllocateApplyOrderOperationTypeEnum;
import com.epoch.app.otsunifiedinventory.model.enums.AllocateOrderStatus;
import com.epoch.app.otsunifiedinventory.sdo.enums.AllocateApplyOrderStatusEnum;
import com.epoch.app.otsunifiedinventory.sdo.enums.AllocateOrderShipTypeEnums;
import com.epoch.app.otsunifiedinventory.sdo.enums.AllocateOrderTypeEnum;
import com.epoch.app.otsunifiedinventory.sdo.enums.AllocateStatusEnum;
import com.epoch.app.otsunifiedinventory.sdo.enums.DocumentReasonEnum;
import com.epoch.app.otsunifiedinventory.sdo.enums.ReasonForRejectionEnum;
import com.epoch.app.otsunifiedinventory.sdo.enums.TransportModeEnum;
import org.apache.commons.lang3.StringUtils;

import java.util.Objects;

public class EnumUtils {

    public static AllocateOrderStatus getAllocateOrderStatusByCode(int code) {
        for (AllocateOrderStatus allocateOrderStatus : AllocateOrderStatus.values()) {
            if (code==allocateOrderStatus.getValue()) {
                return allocateOrderStatus;
            }
        }
        return null;
    }

    public static AllocateOrderTypeEnum getAllocateOrderTypeByCode(Integer type) {
        if (null == type) {
            return null;
        }
        for (AllocateOrderTypeEnum allocateOrderTypeEnum : AllocateOrderTypeEnum.values()) {
            if (allocateOrderTypeEnum.getType().equals(type)) {
                return allocateOrderTypeEnum;
            }
        }
        return null;
    }


    public static DocumentReasonEnum getDocumentReasonByCode(String code) {
        if (StringUtils.isBlank(code)) {
            return null;
        }
        for (DocumentReasonEnum documentReasonEnum : DocumentReasonEnum.values()) {
            if (StringUtils.equalsIgnoreCase(code, documentReasonEnum.getCode())) {
                return documentReasonEnum;
            }
        }
        return null;
    }

    public static String getAllocateStatusEnum(Integer type){
        for (AllocateStatusEnum e : AllocateStatusEnum.values()){
            if (e.getCode().intValue() == type.intValue()){
                return e.getDesc();
            }
        }
        return null;
    }

    public static String getAllocateApplyOrderHeaderEnum(String value){
        for (AllocateApplyOrderHeaderEnum e : AllocateApplyOrderHeaderEnum.values()){
            if (e.getValue().equals(value)){
                return e.getLabel();
            }
        }
        return null;
    }

    public static String getAllocateApplyOrderOperationTypeEnum(Integer type){
        for (AllocateApplyOrderOperationTypeEnum e : AllocateApplyOrderOperationTypeEnum.values()){
            if (e.getValue().equals(type.toString())){
                return e.getLabel();
            }
        }
        return "";
    }



    public static String getAllocateApplyOrderStatusEnum(Integer type){
        for (AllocateApplyOrderStatusEnum e : AllocateApplyOrderStatusEnum.values()){
            if (e.getCode().intValue() == type.intValue()){
                return e.getDesc();
            }
        }
        return null;
    }

    public static TransportModeEnum getTransportModeByCode(String code) {
        if (StringUtils.isBlank(code)) {
            return null;
        }
        for (TransportModeEnum transportModeEnum : TransportModeEnum.values()) {
            if (StringUtils.equalsIgnoreCase(code, transportModeEnum.getCode())) {
                return transportModeEnum;
            }
        }
        return null;
    }

    public static ReasonForRejectionEnum getReasonForRejectionByCode(String code) {
        if (StringUtils.isBlank(code)) {
            return null;
        }
        for (ReasonForRejectionEnum reasonForRejectionEnum : ReasonForRejectionEnum.values()) {
            if (StringUtils.equalsIgnoreCase(code, reasonForRejectionEnum.getCode())) {
                return reasonForRejectionEnum;
            }
        }
        return null;
    }

    public static String getAllocateOrderShipTypeByCode(Integer type){
        for (AllocateOrderShipTypeEnums e : AllocateOrderShipTypeEnums.values()){
            if (e.getType().intValue() == type.intValue()){
                return e.getDesc();
            }
        }
        return null;
    }

    public static String getAllocateOrderType(Integer type){
        if (type == null)return null;
        for (AllocateOrderTypeEnum value : AllocateOrderTypeEnum.values()) {
            if (type.intValue() == value.getType().intValue()){
                return value.getDesc();
            }
        }
        return null;
    }

    public static String getOrderReason(String type){
        for (DocumentReasonEnum value : DocumentReasonEnum.values()) {
            if (Objects.equals(type,value.getCode())){
                return value.getDesc();
            }
        }
        return null;
    }

}
